<?php
/**
 * Created by PhpStorm.
 * User: lgradassi
 * Date: 01.12.2014
 * Time: 15:20
 */


class BCApp {

    public static function GetPageSizeArray() {
        return array(2=>2,10=>10,20=>20,30=>30,40=>40,50=>50);
    }


    public static function GetYouTubeVideoId($url) {
        $video_id = false;
        $url = parse_url($url);
        if(!isset($url['host'])) return false;
        if (strcasecmp($url['host'], 'youtu.be') === 0)
        {
            #### (dontcare)://youtu.be/<video id>
            $video_id = substr($url['path'], 1);
        }
        elseif (strcasecmp($url['host'], 'www.youtube.com') === 0)
        {
            if (isset($url['query']))
            {
                parse_str($url['query'], $url['query']);
                if (isset($url['query']['v']))
                {
                    #### (dontcare)://www.youtube.com/(dontcare)?v=<video id>
                    $video_id = $url['query']['v'];
                }
            }
            if ($video_id == false)
            {
                $url['path'] = explode('/', substr($url['path'], 1));
                if (in_array($url['path'][0], array('e', 'embed', 'v')))
                {
                    #### (dontcare)://www.youtube.com/(whitelist)/<video id>
                    $video_id = $url['path'][1];
                }
            }
        }
        return $video_id;
    }
}